package com.lagou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.entity.CourseComment;
import com.lagou.service.CourseCommentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course/comment")
public class CourseCommentController {

    @Reference
    private CourseCommentService courseCommentService;

    @PostMapping("/saveCourseComment")
    public void saveCourseComment(@RequestBody CourseComment courseComment) {

        courseCommentService.saveComment(courseComment);
    }

    @GetMapping("/getCourseCommentList/{courseId}/{pageIndex}/{pageSize}")
    public List<CourseComment> getCourseCommentList(@PathVariable("courseId") Integer courseId, @PathVariable("pageIndex") Integer pageIndex, @PathVariable("pageSize") Integer pageSize) {

        Integer offset = (pageIndex - 1) * pageSize;
        return courseCommentService.getCommentsByCourseId(courseId, offset, pageSize);
    }

    @GetMapping("/handlerFavorite/{commentId}/{userId}")
    public Integer handlerFavorite(@PathVariable("commentId") Integer commentId, @PathVariable("userId") Integer userId) {

        return courseCommentService.handlerFavorite(commentId, userId);
    }
}
